/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package org.icad.entity;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Gabriel Bran gbran.u@gmail.com
 */
@Entity
@Table(name = "transaccion_contable")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "TransaccionContable.findAll", query = "SELECT t FROM TransaccionContable t"),
    @NamedQuery(name = "TransaccionContable.findByIglesia", query = "SELECT t FROM TransaccionContable t WHERE t.transaccionContablePK.iglesia = :iglesia"),
    @NamedQuery(name = "TransaccionContable.findByFecha", query = "SELECT t FROM TransaccionContable t WHERE t.transaccionContablePK.fecha = :fecha"),
    @NamedQuery(name = "TransaccionContable.findByCorrelativo", query = "SELECT t FROM TransaccionContable t WHERE t.transaccionContablePK.correlativo = :correlativo"),
    @NamedQuery(name = "TransaccionContable.findByConcepto", query = "SELECT t FROM TransaccionContable t WHERE t.concepto = :concepto"),
    @NamedQuery(name = "TransaccionContable.findByMonto", query = "SELECT t FROM TransaccionContable t WHERE t.monto = :monto")})
public class TransaccionContable implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected TransaccionContablePK transaccionContablePK;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 512)
    @Column(name = "concepto")
    private String concepto;
    @Basic(optional = false)
    @NotNull
    @Column(name = "monto")
    private double monto;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "transaccionContable")
    private List<DetalleTransaccion> detalleTransaccionList;
    @JoinColumn(name = "usuario_creacion", referencedColumnName = "codigo")
    @ManyToOne(optional = false)
    private Usuario usuarioCreacion;
    @JoinColumn(name = "iglesia", referencedColumnName = "id", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Iglesia iglesia1;

    public TransaccionContable() {
    }

    public TransaccionContable(TransaccionContablePK transaccionContablePK) {
        this.transaccionContablePK = transaccionContablePK;
    }

    public TransaccionContable(TransaccionContablePK transaccionContablePK, String concepto, double monto) {
        this.transaccionContablePK = transaccionContablePK;
        this.concepto = concepto;
        this.monto = monto;
    }

    public TransaccionContable(int iglesia, Date fecha, int correlativo) {
        this.transaccionContablePK = new TransaccionContablePK(iglesia, fecha, correlativo);
    }

    public TransaccionContablePK getTransaccionContablePK() {
        return transaccionContablePK;
    }

    public void setTransaccionContablePK(TransaccionContablePK transaccionContablePK) {
        this.transaccionContablePK = transaccionContablePK;
    }

    public String getConcepto() {
        return concepto;
    }

    public void setConcepto(String concepto) {
        this.concepto = concepto;
    }

    public double getMonto() {
        return monto;
    }

    public void setMonto(double monto) {
        this.monto = monto;
    }

    @XmlTransient
    public List<DetalleTransaccion> getDetalleTransaccionList() {
        return detalleTransaccionList;
    }

    public void setDetalleTransaccionList(List<DetalleTransaccion> detalleTransaccionList) {
        this.detalleTransaccionList = detalleTransaccionList;
    }

    public Usuario getUsuarioCreacion() {
        return usuarioCreacion;
    }

    public void setUsuarioCreacion(Usuario usuarioCreacion) {
        this.usuarioCreacion = usuarioCreacion;
    }

    public Iglesia getIglesia1() {
        return iglesia1;
    }

    public void setIglesia1(Iglesia iglesia1) {
        this.iglesia1 = iglesia1;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (transaccionContablePK != null ? transaccionContablePK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof TransaccionContable)) {
            return false;
        }
        TransaccionContable other = (TransaccionContable) object;
        if ((this.transaccionContablePK == null && other.transaccionContablePK != null) || (this.transaccionContablePK != null && !this.transaccionContablePK.equals(other.transaccionContablePK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "org.icad.entity.TransaccionContable[ transaccionContablePK=" + transaccionContablePK + " ]";
    }
    
}
